﻿@using ShenNius.Sys.API.Domain.ValueObjects
@{
    ViewData["Title"] = "后台系统设置";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section css{
<style>
    .layui-form-item .layui-input {
        width: 350px;
        padding-right: 10px;
        line-height: 38px;
    }

    .layui-form-item .layui-textarea {
        width: 350px;
    }

    .layui-form-select {
        width: 350px;
    }

    .layui-upload-list {
        margin-top: 10px;
        margin-left: 10%;
    }
</style>
}
@model SysSetting
<form class="layui-form" action="" lay-filter="config-edit">
    <div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form">
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站中文名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="@Model.Name" lay-verify="required" lay-reqtext="网站名称不能为空" placeholder="请输入名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站英文名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="enName" value="@Model.EnName" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">版权:</label>
                    <div class="layui-input-block">
                        <input type="text" name="copyright" placeholder="请填写版权" value="@Model.Copyright" class="layui-input" lay-verify="copyright">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">登录背景图:</label>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test1">上传图片</button>
                        <div class="layui-upload-list" style="width:300px;height:200px;">
                            @if (!string.IsNullOrEmpty(Model.LoginImg))
                            {
                                <img class="layui-upload-img" id="demo1" src="@Model.LoginImg" style="width:100%;height:100%">
                                <input type="hidden" id="loginImg" name="loginImg" class="layui-input" value="@Model.LoginImg">
                            }
                            else
                            {
                                <img class="layui-upload-img" id="demo1" style="width:100%;height:100%">
                                <input type="hidden" id="loginImg" name="loginImg" class="layui-input">
                            }
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">Logo:</label>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test2">上传Logo</button>
                        <div class="layui-upload-list" style="width:150px;height:90px;">
                            @if (!string.IsNullOrEmpty(Model.Logo))
                            {
                                <img class="layui-upload-img" id="demo2" src="@Model.Logo" style="width:100%;height:100%">
                                <input type="hidden" id="logo" name="logo" class="layui-input" value="@Model.Logo">
                            }
                            else
                            {
                                <img class="layui-upload-img" id="demo2" style="width:100%;height:100%">
                                <input type="hidden" id="logo" name="logo" class="layui-input">
                            }
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">favicon:</label>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test3">上传站点图标</button>
                        <div class="layui-upload-list" style="width:50px;height:50px;">
                            @if (!string.IsNullOrEmpty(Model.Favicon))
                            {
                                <img class="layui-upload-img" id="demo3" src="@Model.Favicon" style="width:100%;height:100%">
                                <input type="hidden" id="favicon" name="favicon" class="layui-input" value="@Model.Favicon">
                            }
                            else
                            {
                                <img class="layui-upload-img" id="demo3" style="width:100%;height:100%">
                                <input type="hidden" id="favicon" value="/favicon.ico" name="favicon" class="layui-input">
                            }
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label ">备注信息</label>
                    <div class="layui-input-block">
                        <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息">@Model.Remark</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
@section js{
<script>

    layui.use(['form', 'common','layer','upload'], function () {
            var form = layui.form,
                 $=layui.$,
                layer = layui.layer,
                upload = layui.upload,
                apiUtil = layui.common;

    var obj=function(idDom,imgDom,inputDom,fileDirectory){
       var model= {
            elem: "#"+idDom
            , accept: 'file' //普通文件
            , url: apiUtil.apiUrl() + 'sys/upload/file'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $("#"+imgDom).attr('src', result);
                });
            }
             ,method:"post"
             ,data:{
                 directory:function () {
                            return fileDirectory;
                        },
             }
            , done: function (res) {
                if (res.statusCode==200&&res.success == true) {
                    $("#"+imgDom).attr('src', res.data);
                    $("#"+inputDom).val(res.data);
                }else{
                layer.msg(res.msg);
                return false;
                }
                //上传成功
            }
        }
        return model;
    };

        upload.render(
        obj("test1","demo1","loginImg","sys")
        );
         upload.render(
       obj("test2","demo2","logo","sys")
        );
         upload.render(
         obj("test3","demo3","favicon","")
        );

            // 当前弹出层，防止ID被覆盖
            var parentIndex =  parent.layer.getFrameIndex(window.name);
            form.render();
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                    apiUtil.ajax('sys/config/SettingValue', data.field, "application/json", "post", function (res) {
                        if (res.statusCode == 200 && res.success == true) {
                            apiUtil.success(res.msg);
                            parent.layer.close(parentIndex);
                        } else {
                            apiUtil.error(res.msg);
                        }
                    });

                return false;
            });
        });

</script>

}

